import time
from selenium.webdriver.common.by import By
from pom.base_page import BasePage


class SysManagePage(BasePage):
    def user_manage_page(self):
        self.driver.find_element(By.XPATH, '//*[@id="app"]/div/div[1]/div[2]/div[1]/div/ul/div[2]/li/ul/div[1]').click()

        username = self.driver.find_element(By.XPATH, '//div[1]/div[2]/div[2]/div[3]//tr[1]/td[3]/div').text
        nickname = self.driver.find_element(By.XPATH, '//div/div[1]/div[2]/div[2]/div[3]//tr[1]/td[4]/div').text

        assert username == "admin"
        assert nickname == "超级管理员"

        print(username, nickname, "*********************")

        # search
        time.sleep(1)
        self.driver.find_element(By.XPATH,
                                 '//div[2]/div/div[2]//div/div[1]/div[2]/form/div[1]/div/div/input').send_keys("admin")
        self.driver.find_element(By.XPATH,
                                 '//div[2]/div/div[2]//div/div[1]/div[2]/form/div[2]/div/div/input').send_keys("156")
        self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/div[1]/div[2]/form/div[5]/div/button[1]').click()

        time.sleep(2)
        s_user_name = self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/div[1]/div[2]/div[2]/div['
                                                         '3]//tr/td[3]/div').text
        s_phone_num = self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/div[1]/div[2]/div[2]/div['
                                                         '3]//tr/td[6]/div').text
        print(s_user_name, s_phone_num, "***********************")

        assert s_user_name == "ryadmin"
        assert s_phone_num == "15666666666"

    def role_manage_page(self):
        self.driver.find_element(By.XPATH, '//div[2]/div/div[1]/div[2]/div[1]/div/ul/div[2]/li/ul/div[2]').click()

        role_name = self.driver.find_element(By.XPATH,
                                             '//div[2]/div/div[2]/section/div/div[2]/div[3]//tr[1]/td[3]/div').text
        power_character = self.driver.find_element(By.XPATH,
                                                   '//div[2]/div/div[2]//div/div[2]/div[3]//tr[1]/td[4]/div').text
        print(role_name, power_character, "*************************")

        assert role_name == "公司管理员"
        assert power_character == "companyAdmin"

        # search
        time.sleep(1)
        self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/form/div[1]/div/div/input').send_keys("普通角色")
        self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/form/div[2]/div/div/input').send_keys("common")
        self.driver.find_element(By.XPATH, '//div[2]/div/div[2]/section/div/form/div[5]/div/button[1]').click()

        time.sleep(2)
        s_role_name = self.driver.find_element(By.XPATH,
                                               '//div[2]/div/div[2]/section/div/div[2]/div[3]//tr[1]/td[3]/div').text
        s_power_character = self.driver.find_element(By.XPATH,
                                                     '//div[2]/div/div[2]//div/div[2]/div[3]//tr[1]/td[4]/div').text
        print(s_role_name, s_power_character, "***********************")

        assert s_role_name == "普通角色"
        assert s_power_character == "common"

    def menu_manage_page(self):
        self.driver.find_element(By.XPATH, '//div[2]/div/div[1]/div[2]/div[1]/div/ul/div[2]/li/ul/div[3]').click()
        time.sleep(1)
        self.driver.find_element(By.XPATH, '//div[2]/div/div[2]/section/div/div[2]/div[3]//tr[1]/td[1]/div/div').click()
        time.sleep(1)
        self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/div[2]/div[3]//tr[2]/td[1]/div/div/i').click()

        time.sleep(2)

        order = self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/div[2]/div[3]//tr[3]/td[3]/div').text
        mark = self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/div[2]/div[3]//tr[3]/td[4]/div').text
        path = self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/div[2]/div[3]//tr[3]/td[5]/div').text
        print(order, mark, path, "********************")

        assert order == "1"
        assert mark == "system:user:query"
        assert path == ""

    def department_manage_page(self):
        pass
        # self.driver.find_element(By.XPATH, '//div[2]/div/div[1]/div[2]/div[1]/div/ul/div[2]/li/ul/div[4]').click()

    def post_manage_page(self):
        self.driver.find_element(By.XPATH, '//div[2]/div/div[1]/div[2]/div[1]/div/ul/div[2]/li/ul/div[5]').click()

        time.sleep(1.5)
        num = self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/div[2]/div[3]//tr[1]/td[2]/div').text
        code = self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/div[2]/div[3]//tr[1]/td[3]/div').text
        job_title = self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/div[2]/div[3]//tr[1]/td[4]/div').text

        print(num, code, job_title, "*********************")

        assert num == "1"
        assert code == "ceo"
        assert job_title == "董事长"

        # search
        time.sleep(1)
        self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/form/div[1]/div/div/input').send_keys("user")
        self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/form/div[2]/div/div/input').send_keys("普通")
        self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/form/div[4]/div/button[1]').click()

        time.sleep(2)
        s_num = self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/div[2]/div[3]//tr[1]/td[2]/div').text
        s_code = self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/div[2]/div[3]//tr[1]/td[3]/div').text
        s_job_title = self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/div[2]/div[3]//tr[1]/td[4]/div').text

        print(s_num, s_code, s_job_title, "*********************")

        assert s_num == "4"
        assert s_code == "user"
        assert s_job_title == "普通员工"

    def dict_manage_page(self):
        self.driver.find_element(By.XPATH, '//div[2]/div/div[1]/div[2]/div[1]/div/ul/div[2]/li/ul/div[6]').click()

        time.sleep(1.5)
        dic_num = self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/div[2]/div[3]//tr[1]/td[2]/div').text
        dic_name = self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/div[2]/div[3]//tr[1]/td[3]/div').text
        dic_type = self.driver.find_element(By.XPATH,
                                            '//div[2]/div/div[2]//div/div[2]/div[3]//tr[1]/td[4]/div/a/span').text
        print(dic_num, dic_name, dic_type, "********************")

        assert dic_num == "1"
        assert dic_name == "用户性别"
        assert dic_type == "sys_user_sex"

        # search
        time.sleep(1)
        self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/form/div[1]/div/div/input').send_keys("操作")
        self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/form/div[2]/div/div/input').send_keys("sys")
        self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/form/div[5]/div/button[1]').click()

        time.sleep(2)
        s_dic_num = self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/div[2]/div[3]//tr[1]/td[2]/div').text
        s_dic_name = self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/div[2]/div[3]//tr[1]/td[3]/div').text
        s_dic_type = self.driver.find_element(By.XPATH,
                                              '//div[2]/div/div[2]//div/div[2]/div[3]//tr[1]/td[4]/div/a/span').text
        print(s_dic_num, s_dic_name, s_dic_type, "********************")

        assert s_dic_num == "9"
        assert s_dic_name == "操作类型"
        assert s_dic_type == "sys_oper_type"

    def parameter_setting_page(self):
        self.driver.find_element(By.XPATH, '//div[2]/div/div[1]/div[2]/div[1]/div/ul/div[2]/li/ul/div[7]').click()

        time.sleep(1.5)
        primary_key = self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/div[2]/div[3]//tr[1]/td[2]/div').text
        para_name = self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/div[2]/div[3]//tr[1]/td[3]/div').text
        key_name = self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/div[2]/div[3]//tr[1]/td[4]/div').text
        key_value = self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/div[2]/div[3]//tr[1]/td[5]/div').text

        print(primary_key, para_name, key_name, key_name, "*************")

        assert primary_key == "1"
        assert para_name == "主框架页-默认皮肤样式名称"
        assert key_name == "sys.index.skinName"
        assert key_value == "skin-blue"

        # search
        time.sleep(1)
        self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/form/div[1]/div/div/input').send_keys("验证码")
        self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/form/div[2]/div/div/input').send_keys("account")
        self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/form/div[5]/div/button[1]').click()

        time.sleep(2)
        s_primary_key = self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/div[2]/div[3]//tr[1]/td[2]/div').text
        s_para_name = self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/div[2]/div[3]//tr[1]/td[3]/div').text
        s_key_name = self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/div[2]/div[3]//tr[1]/td[4]/div').text
        s_key_value = self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/div[2]/div[3]//tr[1]/td[5]/div').text

        print(s_primary_key, s_para_name, s_key_name, s_key_name, "*************")

        assert s_primary_key == "4"
        assert s_para_name == "账号自助-验证码开关"
        assert s_key_name == "sys.account.captchaEnabled"
        assert s_key_value == "false"

    def notice_page(self):
        self.driver.find_element(By.XPATH, '//div[2]/div/div[1]/div[2]/div[1]/div/ul/div[2]/li/ul/div[8]').click()

        time.sleep(1.5)
        tittle = self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/div[2]/div[3]//tr[1]/td[3]/div').text
        notice_type = self.driver.find_element(By.XPATH,
                                               '//div[2]/div/div[2]//div/div[2]/div[3]//tr[1]/td[4]/div/div/span').text
        status = self.driver.find_element(By.XPATH,
                                          '//div[2]/div/div[2]//div/div[2]/div[3]//tr[1]/td[5]/div/div/span').text
        print(tittle, notice_type, status)

        assert tittle == "温馨提醒：2018-07-01 新版本发布啦"
        assert notice_type == "公告"
        assert status == "正常"

    def log_manage_page(self):
        pass

        # self.driver.find_element(By.XPATH, '//div[2]/div/div[1]/div[2]/div[1]/div/ul/div[2]/li/ul/div[9]').click()
        # time.sleep(1)
        # self.driver.find_element(By.XPATH, '//div/div[1]/div[2]/div[1]/div/ul/div[2]/li/ul/div[9]/li/ul/div[1]/a/li').click()
        #
        # time.sleep(1.5)
        # log_num = self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/div[2]/div[3]//tr[1]/td[2]/div').text
        # sys_modular = self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/div[2]/div[3]//tr[1]/td[3]/div').text
        # request_method = self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/div[2]/div[3]//tr[1]/td[5]/div').text
        # print(log_num, sys_modular, request_method, "**********")
        #
        # assert log_num == "2180"
        # assert sys_modular == "日志"
        # assert request_method == "POST"
        #
        # time.sleep(1)
        # self.driver.find_element(By.XPATH, '//div/div[1]/div[2]/div[1]/div/ul/div[2]/li/ul/div[9]/li/ul/div[2]/a/li').click()
        #
        # time.sleep(3)
        # visit_num = self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/div[2]/div[3]//tr[1]/td[2]/div').text
        # user_name = self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/div[2]/div[3]//tr[1]/td[3]/div').text
        # login_addr = self.driver.find_element(By.XPATH, '//div[2]/div/div[2]//div/div[2]/div[3]//tr[1]/td[4]/div').text
        # print(visit_num, user_name, login_addr, '************')
        #
        # assert visit_num == "1591"
        # assert user_name == "admin"
        # assert login_addr == "192.168.43.170"
